@extends('admin.layouts.app')
@section('css')
        <!-- Custombox css -->
       
        <link href="{{asset('admin/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css')}}" rel="stylesheet">
         
@endsection 

@section('content')

                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">租赁信息管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="{{url('zadmin')}}">系统</a></li>
                                    <li><a href="{{url('zadmin/rent')}}">租赁信息管理</a></li>
                                    <li class="active">修改租赁信息</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                        	<div class="col-lg-12">
                        		<div class="card-box">
                                     @if(session('rs') || $errors->any())
                              <div class="alert alert-{{session('rs')['status']}}">
                        @if($errors->any())
                            @foreach($errors->messages() as $msg )
                                {{$msg[0]}}
                            @endforeach
                        @endif
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif
                          
                          
                            
                        			<div class="row">
			                        	<div class="col-md-12">
                                  <form class="form-horizontal" role="form" action="{{url('zadmin/rent/'.$data->id)}}" method="post" enctype="multipart/form-data">{{ method_field('PUT') }}
                            {{ csrf_field()}}
                            <div class="row">
                                
                            

                            <div class="col-lg-12">
                                <div class="panel panel-border panel-info">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">修改租赁信息</h3>
                                    </div>
                                    <div class="panel-body">
                                        
                                        <div class="row">
                                        
                                            <div class="form-group col-md-4">
                                                <label class="col-md-3">客户名称<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="name" value="{{$data->name}}" />
                                                </div>
                                             </div>
                                             <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">电话<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="mobile" required="" value="{{$data->mobile}}" />
                                                 </div>
                                                
                                            </div>

                                             <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">联系人<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="contacter" required="" value="{{$data->contacter}}" />
                                                 </div>
                                                
                                            </div>
                                        </div>
                                        <div class="row">    
                                        
                                            <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">车牌号<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="car_num" required="" value="{{$data->car_num}}" />
                                                 </div>
                                                
                                            </div>
                                            <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">车型<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="car_model" required="" value="{{$data->car_model}}" />
                                                 </div>
                                                
                                            </div>

                                             <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">车辆来源<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="source" required="" value="{{$data->source}}" />
                                                 </div>
                                                
                                            </div>
                                        </div>
                                         <div class="row">    
                                        
                                            <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">租入押金<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="in_yajin" required="" value="{{$data->in_yajin}}" />
                                                 </div>
                                                
                                            </div>
                                            <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">租入租金<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="in_price" required="" value="{{$data->in_price}}" />
                                                 </div>
                                                
                                            </div>

                                             <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">租入发票<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="in_fapiao" required="" value="{{$data->in_fapiao}}" />
                                                 </div>
                                                
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="form-group col-md-6">
                                                <label class="col-md-3">租赁开始日期<span class="text-danger">*</span></label>
                                                <div class="col-md-9"> 
                                                <input class="form-control date" required="" name="rent_begin" value="{{$data->rent_begin}}"  /> 
                                                </div>
                                            </div>
                                             <div class="form-group col-md-6">
                                                <label class="col-md-3">租赁结束日期<span class="text-danger">*</span></label>
                                                <div class="col-md-9"> 
                                                <input class="form-control date" required="" name="rent_end" value="{{$data->rent_end}}"  /> 
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="form-group col-md-4">
                                                <label class="col-md-3">合同期限<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                    <input name="hetong_qixian" readonly="" class="form-control" value="{{$data->hetong_qixian}}" />
                                                    
                                                    
                                                </div> 
                                            </div>
                                            <div class="form-group col-md-4">
                                                <label class="col-md-3">付款方式<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                    <input name="pay_type" class="form-control" value="{{$data->pay_type}}" />
                                                    
                                                    
                                                </div> 
                                            </div>
                                            <div class="form-group col-md-4">
                                                <label class="col-md-3">充电设备<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                    <input name="charge_dev" class="form-control" value="{{$data->charge_dev}}" />
                                                    
                                                    
                                                </div> 
                                            </div>
                                        </div>

                                        <div class="row">    
                                        
                                            <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">租出押金<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="out_yajin" required="" value="{{$data->out_yajin}}" />
                                                 </div>
                                                
                                            </div>
                                            <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">租出租金<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="out_price" required="" value="{{$data->out_price}}" />
                                                 </div>
                                                
                                            </div>

                                             <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">租出发票<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="out_fapiao" required="" value="{{$data->out_fapiao}}" />
                                                 </div>
                                                
                                            </div>
                                        </div>

                                        <div class="row">    
                                        
                                            <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">收款日期<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control date" name="shoukuan_date" required="" value="{{$data->shoukuan_date}}" />
                                                 </div>
                                                
                                            </div>
                                            <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">下次付款日期<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control date" name="next_pay_date" required="" value="{{$data->next_pay_date}}" />
                                                 </div>
                                                
                                            </div>

                                             <div class="form-group col-md-4">
                                                
                                                <label class="col-md-3">下次付款金额<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input class="form-control" name="next_pay_price" required="" value="{{$data->next_pay_price}}" />
                                                 </div>
                                                
                                            </div>
                                        </div>
                                        <div class="row">   

                                           
                                            <div class="form-group col-md-4">
                                                <label class="col-md-3">审车到期日</label>
                                                <div class="col-md-9">
                                                <input class="form-control date" name="shenche_date" value="{{$data->shenche_date}}" /> 
                                                </div>
                                            </div>
                                       
                                             <div class="form-group col-md-4">
                                                <label class="col-md-3">交强险到期日</label>
                                                <div class="col-md-9"> 
                                                <input class="form-control date" name="jiaoqiangxian_date" value="{{$data->jiaoqiangxian_date}}"  /> 
                                                </div>
                                            </div>
                                            <div class="form-group col-md-4">
                                                <label class="col-md-3">商业险到期日</label>
                                                <div class="col-md-9">
                                                <input class="form-control date" name="shangyexian_date" value="{{$data->shangyexian_date}}" /> 
                                                </div>
                                            </div>
                                        </div>
                                        <div class="row">
                                        <div class="form-group col-md-6">
                                          <label class="col-md-1">业务员</label>
                                          <div class="col-md-11">
                                                <input class="form-control " name="yewuyuan" value="{{$data->yewuyuan}}" />
                                          </div>       
                                            </div>    
                                            <div class="form-group col-md-6">
                                          <label class="col-md-1">备注</label>
                                          <div class="col-md-11">
                                                <input class="form-control " name="remark" value="{{$data->remark}}" />
                                          </div>       
                                            </div>
                                            

                                        </div>

                                        <div class="row">    
                                        
                                           
                                             <div class="form-group col-md-6">
                                                
                                                <label class="col-md-3">合同推送状态<span class="text-danger">*</span></label>
                                                <div class="col-md-9">
                                                 <input type="radio" name="status" value="1"  {{$data->status==1?'checked=""':''}} />继续推送
                                                 <input type="radio" name="status" value="-1" {{$data->status==-1?'checked=""':''}} />停止推送
                                                 </div>
                                                
                                            </div>

                                           
                                            
                                        </div>
                                   
                                           
                                       
                                       
                                        
                                        
                                      
                                    </div>
                                </div>
                            </div>

                            

                             

                            <div class="col-lg-12">
                                <div class="form-group text-center">                                                
                                    <button type="submit" class="btn btn-info waves-effect waves-light">保存更新</button>
                                </div>
                            </div>                           
                        </div>




                                

                                        

                                    </div>

                                </div>


                            </div>


                            
                        
                        </form>
                                </div>
			                        	
			                        </div>

                             
			                        
                        			
                        		</div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
    @section('modal')        
      
    @endsection        
       

           



    
        @section('js')
       

<script type="text/javascript" src="{{asset('admin/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js')}}"></script>
<script type="text/javascript" src="{{asset('admin/plugins/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js')}}" charset="UTF-8"></script>
<script type="text/javascript">
$(document).ready(function () {  
    $(".serviceitem tr").find("select").select2();
    $('.departitem tr').find("select").select2();

    $(document).on('click','.btn-add',function(){
            $('.serviceitem tr').eq(0).find('select')
                                .select2("destroy").css('width','200px');
            var tr = $('.serviceitem tr').eq(0).clone();
           
            $('.serviceitem').append(tr);
            tr.find('select').select2();
            $('.serviceitem tr').eq(0).find('select').select2();
    });


    $(document).on('click','.btn-add-depart',function(){
            $('.departitem tr').eq(0).find('select')
                                .select2("destroy").css('width','200px');
            var tr = $('.departitem tr').eq(0).clone();          
         
            $('#depart').append(tr);
            tr.find('select').select2();
            $('.departitem tr').eq(0).find('select').select2();
            
            
    });
});    
    $(document).on('click','.btn-remove-service',function(){
        var tr_len = $('.serviceitem tr').length;
        if(tr_len>1) {
            $(this).parents('tr').remove();    
        }
        
    })

    
    $(document).on('click','.btn-remove-depart',function(){
        var tr_len = $('.departitem tr').length;
        if(tr_len>1) {
            $(this).parents('tr').remove();    
        }
        $(this).parents('tr').remove();
    })

    

    $('.date').datepicker({
        format: "yyyy-mm-dd",
        autoclose: true,
        todayBtn: true,
        language: 'zh-CN'
        //startDate: new Date()
       
    });

    $('#client_id').on('change',function(){
        var client_id = $(this).val();
        var url = "{{url('api/cars')}}";
       
        $.get(url,{'client_id':client_id},function(rs){
            if(rs.status==true) {
                var opt = '';
                $.each(rs.data,function(k,v){
                    opt = opt+'<option value="'+v.id+'">'+v.car_num+'</option>'
                });
                $('#car_id').append(opt);
            }
        })
    });

    $(document).on('change','.service_type',function(){
        var _this = $(this);
        var type_id = _this.val();
        var url = "{{url('api/services')}}";
        $.get(url,{'type_id':type_id},function(rs){
            if(rs.status==true) {
                var service = _this.parents('tr').find('.service_id');
                service.empty();
                var opt = '<option value="">请选择</option>';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'" data-price="'+v.price+'">'+v.name+'</option>'; 
                });
                 service.append(opt);
                
            }
        })
    });

    $(document).on('change','.service_id',function(){
        var _this = $(this);
        var price = _this.find("option:selected").data('price')
        //alert(price);
        _this.parents('tr').find('.service_price').val(price);
        
        
    });

    $(document).on('change','.depart_cate',function(){
        var _this = $(this);
        var cate_id = _this.val();
        var url = "{{url('api/departs')}}";
        $.get(url,{'cate_id':cate_id},function(rs){
            if(rs.status==true) {
                var depart = _this.parents('tr').find('.depart_id');
                depart.empty();
                var opt = '<option value="">请选择</option>';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'" data-price="'+v.out_price+'" data-num="'+v.store_num+'">'+v.name+'</option>'; 
                });
                 depart.append(opt);
                
            }
        })
    });

    $(document).on('change','.depart_id',function(){
        var _this = $(this);
        var price = _this.find("option:selected").data('price');
        var  num = _this.parents('tr').find('.depart_num').val();
        var store_num = _this.find("option:selected").data("num");
        if(store_num<5) {
            alert('库存小于5，请及时补充');
        }
        subTotal = num*price;
        _this.parents('tr').find('.total_price').val(subTotal);
        
    });

    $(document).on('click','.total_price',function(){
        var _this = $(this);
        var num   = _this.parents('tr').find('.depart_num').val();
        var price = _this.parents('tr').find('.depart_id option:selected').data("price");
        
        if(price==undefined) {
            alert('请选择配件');return ;
        }
        _this.val(price*num);
    });

    $(document).on('click','.service_price',function(){
        var _this = $(this);
        
        var price = _this.parents('tr').find('.service_id option:selected').data("price");
        //alert(price);
        if(price==undefined) {
            alert('请选择配件');return ;
        }
        _this.val(price);
    });
    




         

         
        </script>
@endsection
    
